//
//  UserServices.m
//  Les
//
//  Created by 朱亮亮 on 14-11-4.
//  Copyright (c) 2014年 朱 亮亮. All rights reserved.
//

#import "UserServices.h"
#import "BMNetworkHandler.h"
#import "SVProgressHUD.h"
#import "DES3Util.h"
#import "DataModel.h"
#import "NSObjectAdditions.h"
//#import <Category/NSString+Category.h>

#define publicKey @"E1D6849E"  //公钥

@implementation UserServices

+ (void)loginByUsername:(NSString *)username
                   pass:(NSString *)pass
        completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];
    [params setValue:username forKey:@"username"];
    [params setValue:pass forKey:@"pass"];
    [[BMNetworkHandler sharedInstance] conURL:LOGIN
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         completionBlock(API_Request_Success, returnData);
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    //completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)unloginByToken:(NSString *)token
       completionBlock:(void (^)(int, id))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];
    [params setValue:token forKey:@"token"];
    [[BMNetworkHandler sharedInstance] conURL:LOGIGN_OUT
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         completionBlock(API_Request_Success, returnData);
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)auditByToken:(NSString *)username
            pageSize:(NSString *)pageSize
                page:(NSString *)page
                sign:(NSString *)sign
                name:(NSString *)name
            servicer:(NSString *)servicer
     completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];
    [params setValue:username forKey:@"token"];
    [params setValue:pageSize forKey:@"pageSize"];
    [params setValue:page forKey:@"page"];
    [params setValue:sign forKey:@"sign"];
    [params setValue:name forKey:@"name"];
    [params setValue:servicer forKey:@"servicer"];
    [[BMNetworkHandler sharedInstance] conURL:AUDIT_LIST
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:&error];
                                         completionBlock(API_Request_Success, returnData);
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

//信息列表
+ (void)getAuditListByToken:(NSString *)token
                   pageSize:(NSString *)pageSize
                       page:(NSString *)page sign:(NSString *)sign
                       name:(NSString *)name
                   servicer:(NSString *)servicer
            completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];
    [params setValue:token forKey:@"token"];
    [params setValue:pageSize forKey:@"pageSize"];
    [params setValue:page forKey:@"page"];
    [params setValue:sign forKey:@"sign"];
    [params setValue:name forKey:@"name"];
    [params setValue:servicer forKey:@"servicer"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/website/list", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:&error];
                                         completionBlock(API_Request_Success, returnData);
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

//门店签约信息列表 详情
+ (void)getAuditListByToken:(NSString *)token
                         id:(NSString *)id1
            completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/website/view", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:&error];
                                         completionBlock(API_Request_Success, returnData);
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}


+ (void)auditBytoken:(NSString *)token
                  id:(NSString *)id1
     completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [[BMNetworkHandler sharedInstance] conURL:AUDIT_REQUEST
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:&error];
                                         completionBlock(API_Request_Success, returnData);
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)auditOptBytoken:(NSString *)token
                     id:(NSString *)id1
                 status:(NSString *)status
        completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [params setValue:status forKey:@"status"];
    [[BMNetworkHandler sharedInstance] conURL:AUDIT_Opt
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         completionBlock(API_Request_Success, returnData);
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)auditResonOptBytoken:(NSString *)token
                          id:(NSString *)id1
                      status:(NSString *)status
                       reson:(NSString *)reson
             completionBlock:(void (^)(int, id))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [params setValue:status forKey:@"status"];
    [params setValue:reson forKey:@"reson"];
    [[BMNetworkHandler sharedInstance] conURL:AUDIT_ResonOpt
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         completionBlock(API_Request_Success, returnData);
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

//获取号池列表和对应权限的渠道经理列表
+ (void)getNumPoolListByToken:(NSString *)token
                     servicer:(NSString *)servicer
                         page:(NSString *)page
                     pagesize:(NSString *)pagesize
              completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:servicer forKey:@"servicer"];
    [params setValue:page forKey:@"page"];
    [params setValue:pagesize forKey:@"pageSize"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/mobilePool/list", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             CommonModel *result = [[CommonModel alloc] initWithDictionary:dictionary error:nil];
                                             completionBlock(API_Request_Success, result);
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

//号池添加请求数据
+ (void)getNumPoolAddByToken:(NSString *)token
             completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/mobilePool/add", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             CommonModel *result = [[CommonModel alloc] initWithDictionary:dictionary error:nil];
                                             completionBlock(API_Request_Success, result);
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

//号池添加请求
+ (void)addNumPoolByMobile:(NSString *)mobile
                  servicer:(NSString *)servicer
                     token:(NSString *)token
           completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:mobile forKey:@"mobile"];
    [params setValue:servicer forKey:@"servicer"];
    [params setValue:token forKey:@"token"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/mobilePool/add", API_HOST]
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     NSArray *array = returnData;
                                     NSDictionary *dictionary = array[0];
                                     NSString *msg = [dictionary objectForKey:@"msg"];
                                     NSString *flag = [dictionary objectForKey:@"flag"];
                                     if ([@"0" isEqualToString:flag]) {
                                         completionBlock(API_Request_Success, nil);
                                     } else {
                                         [SVProgressHUD showErrorWithStatus:msg];
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

//号池修改请求数据
+ (void)getNumPoolEditByToken:(NSString *)token poolId:(NSString *)poolId completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:poolId forKey:@"id"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/mobilePool/edit", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             CommonModel *result = [[CommonModel alloc] initWithDictionary:dictionary error:nil];
                                             completionBlock(API_Request_Success, result);
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

//号池修改请求
+ (void)editNumPoolByMobile:(NSString *)mobile
                   servicer:(NSString *)servicer
                      token:(NSString *)token
                     poolId:(NSString *)poolId completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:mobile forKey:@"mobile"];
    [params setValue:servicer forKey:@"servicer"];
    [params setValue:poolId forKey:@"id"];
    [params setValue:token forKey:@"token"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/mobilePool/edit", API_HOST]
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     completionBlock(API_Request_Success, nil);
                                     NSArray *array = returnData;
                                     NSDictionary *dictionary = array[0];
                                     NSString *msg = [dictionary objectForKey:@"msg"];
                                     NSString *flag = [dictionary objectForKey:@"flag"];
                                     if ([@"0" isEqualToString:flag]) {
                                         completionBlock(API_Request_Success, nil);
                                     } else {
                                         [SVProgressHUD showErrorWithStatus:msg];
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}


+ (void)deletePoolByToken:(NSString *)token poolId:(NSString *)poolId completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:poolId forKey:@"id"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/mobilePool/del", API_HOST]
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     NSArray *array = returnData;
                                     NSDictionary *dictionary = array[0];
                                     NSString *msg = [dictionary objectForKey:@"msg"];
                                     NSString *flag = [dictionary objectForKey:@"flag"];
                                     if ([@"0" isEqualToString:flag]) {
                                         completionBlock(API_Request_Success, nil);
                                     } else {
                                         [SVProgressHUD showErrorWithStatus:msg];
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}


//消息处理列表请求
+ (void)getMsgListByToken:(NSString *)token
                    title:(NSString *)title
                     page:(NSString *)page
                 pagesize:(NSString *)pagesize
          completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:title forKey:@"title"];
    [params setValue:page forKey:@"page"];
    [params setValue:pagesize forKey:@"pagesize"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/message/list", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             CommonModel *result = [[CommonModel alloc] initWithDictionary:dictionary error:nil];
                                             completionBlock(API_Request_Success, result);
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}


//编辑消息请求
+ (void)editMsgByToken:(NSString *)token
                 msgId:(NSString *)msgId
               recUser:(NSString *)recUser
               message:(NSString *)message
                 title:(NSString *)title
       completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:recUser forKey:@"recUsers"];
    [params setValue:message forKey:@"message"];
    [params setValue:title forKey:@"title"];
    [params setValue:msgId forKey:@"id"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/message/edit", API_HOST]
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     completionBlock(API_Request_Success, nil);
                                     NSArray *array = returnData;
                                     NSDictionary *dictionary = array[0];
                                     NSString *msg = [dictionary objectForKey:@"msg"];
                                     NSString *flag = [dictionary objectForKey:@"flag"];
                                     if ([@"0" isEqualToString:flag]) {
                                         completionBlock(API_Request_Success, nil);
                                     } else {
                                         [SVProgressHUD showErrorWithStatus:msg];
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

//新建消息请求
+ (void)newMsgByToken:(NSString *)token
              recUser:(NSString *)recUser
              message:(NSString *)message
                title:(NSString *)title
      completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:recUser forKey:@"recUsers"];
    [params setValue:message forKey:@"message"];
    [params setValue:title forKey:@"title"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/message/add", API_HOST]
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     completionBlock(API_Request_Success, nil);
                                     NSArray *array = returnData;
                                     NSDictionary *dictionary = array[0];
                                     NSString *msg = [dictionary objectForKey:@"msg"];
                                     NSString *flag = [dictionary objectForKey:@"flag"];
                                     if ([@"0" isEqualToString:flag]) {
                                         completionBlock(API_Request_Success, nil);
                                     } else {
                                         [SVProgressHUD showErrorWithStatus:msg];
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

//删除消息请求
+ (void)deleteMsgByToken:(NSString *)token
                   msgId:(NSString *)msgId
         completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:msgId forKey:@"id"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/message/del", API_HOST]
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSArray *array = returnData;
                                         NSDictionary *dictionary = array[0];
                                         NSString *msg = [dictionary objectForKey:@"msg"];
                                         NSString *flag = [dictionary objectForKey:@"flag"];
                                         if ([@"0" isEqualToString:flag]) {
                                             completionBlock(API_Request_Success, nil);
                                         } else {
                                             [SVProgressHUD showErrorWithStatus:msg];
                                         }
                                         completionBlock(API_Request_Success, nil);
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

//消息推送目标list add情况的
+ (void)getMsgPushList:(NSString *)token completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/message/add", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             NSArray *result = [dictionary objectForKey:@"webUserList"];
                                             NSMutableArray *list = [NSMutableArray array];
                                             [result enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
                                                 MsgReceiveModel *model = [[MsgReceiveModel alloc] initWithDictionary:obj error:nil];
                                                 if (model)
                                                     [list addObject:model];
                                             }];
                                             completionBlock(API_Request_Success, list);
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

//消息推送目标list edit情况的
+ (void)getMsgEditPushList:(NSString *)token
                     msgId:(NSString *)msgId
           completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:msgId forKey:@"id"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/message/edit", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:YES
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             NSArray *result = [dictionary objectForKey:@"webUserList"];
                                             NSMutableArray *list = [NSMutableArray array];
                                             [result enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
                                                 MsgReceiveModel *model = [[MsgReceiveModel alloc] initWithDictionary:obj error:nil];
                                                 if (model)
                                                     [list addObject:model];
                                             }];
                                             completionBlock(API_Request_Success, list);
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}


+ (void)orderAuditListByToken:(NSString *)token
                           id:(NSString *)id1
                         sign:(NSString *)sign
                         type:(NSString *)type
                         page:(NSString *)page
                     pageSize:(NSString *)pageSize
                   showDialog:(BOOL)showDialog
              completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [params setValue:sign forKey:@"sign"];
    [params setValue:type forKey:@"type"];
    [params setValue:pageSize forKey:@"pageSize"];
    [params setValue:page forKey:@"page"];
    // todo BruceDuan
    //[[BMNetworkHandler sharedInstance] conURL:@"http://localhost:8080/order/auditList.json" //指定文件夹启动一个http-server -h ;http-server -p 8080
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/order/auditList", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             if ([dictionary objectForKey:@"msg"]) {
                                                 NSString *msg = [dictionary objectForKey:@"msg"];
                                                 [SVProgressHUD showInfoWithStatus:msg];
                                                 if ([msg containsString:@"非法"]) {
                                                     [[AppDelegate appDelegate] toLogin];
                                                 }
                                                 completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                                 return;
                                             } else {
                                                 completionBlock(API_Request_Success, returnData);
                                             }
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)orderAuditDetailByToen:(NSString *)token
                            id:(NSString *)id1
                          sign:(NSString *)sign
                          type:(NSString *)type
                    showDialog:(BOOL)showDialog
               completionBlock:(void (^)(int, id))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/order/confirm", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             if ([dictionary objectForKey:@"msg"]) {
                                                 NSString *msg = [dictionary objectForKey:@"msg"];
                                                 [SVProgressHUD showInfoWithStatus:msg];
                                                 if ([msg containsString:@"非法"]) {
                                                     [[AppDelegate appDelegate] toLogin];
                                                 }
                                                 completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                                 return;
                                             } else {
                                                 completionBlock(API_Request_Success, returnData);
                                             }
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)orderAuditConfirmSjAmoutByToken:(NSString *)token
                                     id:(NSString *)id1
                                basicId:(NSString *)basicId
                               sjAmount:(NSString *)sjAmount
                             showDialog:(BOOL)showDialog
                        completionBlock:(void (^)(int, id))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:basicId forKey:@"basicId"];
    [params setValue:id1 forKey:@"id"];
    [params setValue:sjAmount forKey:@"sjAmount"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/order/confirmOpt", API_HOST]
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(NSData *returnData) {
                                     if (completionBlock) {
                                         NSArray *array = returnData;
                                         NSDictionary *dictionary = array[0];
                                         NSString *msg = [dictionary objectForKey:@"msg"];
                                         NSString *flag = [dictionary objectForKey:@"flag"];
                                         if ([@"0" isEqualToString:flag]) {
                                             [SVProgressHUD showSuccessWithStatus:msg];
                                             completionBlock(API_Request_Success, nil);
                                         } else {
                                             [SVProgressHUD showErrorWithStatus:msg];
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)orderAuditConfirmHaoKaByToken:(NSString *)token
                               mobile:(NSString *)mobile
                                   id:(NSString *)id1
                              basicId:(NSString *)basicId
                           showDialog:(BOOL)showDialog
                      completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:basicId forKey:@"basicId"];
    [params setValue:id1 forKey:@"id"];
    [params setValue:mobile forKey:@"mobile"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/order/confirmOpt", API_HOST]
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(NSData *returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         // returnData = [NSJSONSerialization JSONObjectWithData:(NSData *) returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = ((NSArray *) returnData)[0];
                                             if ([dictionary objectForKey:@"msg"]) {
                                                 NSString *msg = [dictionary objectForKey:@"msg"];
                                                 //[SVProgressHUD showInfoWithStatus:msg];
                                                 if ([msg containsString:@"非法"]) {
                                                     [[AppDelegate appDelegate] toLogin];
                                                     completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                                     return;
                                                 }
                                                 completionBlock(API_Request_Success, returnData);
                                             } else {
                                                 completionBlock(API_Request_Success, returnData);
                                             }
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)orderAuditDetailByToen:(NSString *)token
                            id:(NSString *)id1
                    showDialog:(BOOL)showDialog
               completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/order/audit", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             if ([dictionary objectForKey:@"msg"] != nil) {
                                                 NSString *msg = [dictionary objectForKey:@"msg"];
                                                 [SVProgressHUD showInfoWithStatus:msg];
                                                 if ([msg containsString:@"非法"]) {
                                                     [[AppDelegate appDelegate] toLogin];
                                                 }
                                                 completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                                 return;
                                             } else {
                                                 completionBlock(API_Request_Success, returnData);
                                             }
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)orderAuditOpttByToken:(NSString *)token
                           id:(NSString *)id1
                      basicId:(NSString *)basicId
                       status:(NSString *)status
                        reson:(NSString *)reson
                   showDialog:(BOOL)showDialog
              completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:basicId forKey:@"basicId"];
    [params setValue:status forKey:@"status"];
    [params setValue:reson forKey:@"reson"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/order/auditOpt", API_HOST]
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         //returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             //returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                             NSDictionary *dictionary = returnData[0];
                                             if ([dictionary objectForKey:@"msg"]) {
                                                 NSString *msg = dictionary[@"msg"];
                                                 [SVProgressHUD showInfoWithStatus:msg];
                                                 if ([msg containsString:@"非法"]) {
                                                     [[AppDelegate appDelegate] toLogin];
                                                     completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                                 } else {
                                                     completionBlock(API_Request_Success, returnData);
                                                 }
                                             } else {
                                                 completionBlock(API_Request_Success, returnData);
                                             }
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}


+ (void)orderAuditOptByToken:(NSString *)token
                          id:(NSString *)id1
                     basicId:(NSString *)basicId
                    sjAmount:(NSString *)sjAmount
                  showDialog:(BOOL)showDialog
             completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [params setValue:basicId forKey:@"basicId"];
    [params setValue:sjAmount forKey:@"sjAmount"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/order/auditOpt", API_HOST]
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(NSData *returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:(NSData *) returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = ((NSArray *) returnData)[0];
                                             if ([dictionary objectForKey:@"msg"]) {
                                                 NSString *msg = [dictionary objectForKey:@"msg"];
                                                 [SVProgressHUD showInfoWithStatus:msg];
                                                 if ([msg containsString:@"非法"]) {
                                                     [[AppDelegate appDelegate] toLogin];
                                                 }
                                                 completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                                 return;
                                             } else {
                                                 completionBlock(API_Request_Success, returnData);
                                             }
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)orderAuditFahuoByToen:(NSString *)token
                           id:(NSString *)id1
                   showDialog:(BOOL)showDialog
              completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/order/fahuo", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             if ([dictionary objectForKey:@"msg"]) {
                                                 NSString *msg = [dictionary objectForKey:@"msg"];
                                                 [SVProgressHUD showInfoWithStatus:msg];
                                                 if ([msg containsString:@"非法"]) {
                                                     [[AppDelegate appDelegate] toLogin];
                                                 }
                                                 completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                                 return;
                                             } else {
                                                 completionBlock(API_Request_Success, returnData);
                                             }
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)orderAuditOptByToken:(NSString *)token
                     basicId:(NSString *)basicId
                         opt:(NSString *)opt
                 expressName:(NSString *)expressName
                  expressNum:(NSString *)expressNum
               expressRemark:(NSString *)expressRemark
                    sendType:(NSString *)sendType
                  showDialog:(BOOL)showDialog
             completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:basicId forKey:@"basicId"];
    [params setValue:opt forKey:@"opt"];
    [params setValue:expressName forKey:@"expressNum"];
    [params setValue:expressNum forKey:@"expressNum"];
    [params setValue:expressRemark forKey:@"expressRemark"];
    [params setValue:sendType forKey:@"sendType"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/order/fahuoOpt", API_HOST]
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         if ([@"fahuo" isEqualToString:[params objectForKey:@"opt"]]) {
                                             completionBlock(API_Request_Success, returnData);//奇葩接口直接成功
                                         } else {
                                             NSArray *array = returnData;
                                             NSDictionary *dictionary = array[0];
                                             NSString *msg = [dictionary objectForKey:@"msg"];
                                             NSString *flag = [dictionary objectForKey:@"flag"];
                                             if ([@"0" isEqualToString:flag]) {
                                                 [SVProgressHUD showSuccessWithStatus:msg];
                                                 completionBlock(API_Request_Success, nil);
                                             } else {
                                                 [SVProgressHUD showErrorWithStatus:msg];
                                             }
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)orderAuditGetPoolsByToken:(NSString *)token
                          segment:(NSString *)segment
                       showDialog:(BOOL)showDialog
                  completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:segment forKey:@"segment"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/order/getPools", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         NSMutableArray *list = [NSMutableArray array];
                                         if ([returnData isNSArray] && ((NSArray *) returnData).count == 0) {
                                             completionBlock(API_Request_Success, list);
                                         } else {
                                             if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                                 NSArray *result = returnData;

                                                 [result enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
                                                     OrderDealDetailPoolList *model = [[OrderDealDetailPoolList alloc] initWithDictionary:obj error:nil];
                                                     if (model)
                                                         [list addObject:model];
                                                 }];
                                                 completionBlock(API_Request_Success, list);
                                             } else {
                                                 completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                             }
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)orderListByToken:(NSString *)token
                      id:(NSString *)id1
                    sign:(NSString *)sign
                    type:(NSString *)type
                    page:(NSString *)page
                pageSize:(NSString *)pageSize
              showDialog:(BOOL)showDialog
         completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [params setValue:sign forKey:@"sign"];
    [params setValue:type forKey:@"type"];
    [params setValue:pageSize forKey:@"pageSize"];
    [params setValue:page forKey:@"page"];
    // todo BruceDuan
    //[[BMNetworkHandler sharedInstance] conURL:@"http://localhost:8080/order/auditList.json" //指定文件夹启动一个http-server -h ;http-server -p 8080
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/order/list", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             if ([dictionary objectForKey:@"msg"]) {
                                                 NSString *msg = [dictionary objectForKey:@"msg"];
                                                 [SVProgressHUD showInfoWithStatus:msg];
                                                 if ([msg containsString:@"非法"]) {
                                                     [[AppDelegate appDelegate] toLogin];
                                                 }
                                                 completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                                 return;
                                             } else {
                                                 completionBlock(API_Request_Success, returnData);
                                             }
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

#pragma mark  ------- 后台业务处理--------------------

+ (void)blackListByToken:(NSString *)token
                   title:(NSString *)title
               recUserId:(NSString *)recUserId
                  userId:(NSString *)userId
                    page:(NSString *)page
                pageSize:(NSString *)pageSize
              showDialog:(BOOL)showDialog
         completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:title forKey:@"title"];
    [params setValue:recUserId forKey:@"recUserId"];
    [params setValue:userId forKey:@"userId"];
    [params setValue:pageSize forKey:@"pageSize"];
    [params setValue:page forKey:@"page"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/black/list", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             if ([dictionary objectForKey:@"msg"]) {
                                                 NSString *msg = [dictionary objectForKey:@"msg"];
                                                 [SVProgressHUD showInfoWithStatus:msg];
                                                 if ([msg containsString:@"非法"]) {
                                                     [[AppDelegate appDelegate] toLogin];
                                                 }
                                                 completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                                 return;
                                             } else {
                                                 completionBlock(API_Request_Success, returnData);
                                             }
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)blackDealToken:(NSString *)token
                    id:(NSString *)id1
                backId:(NSString *)backId
            showDialog:(BOOL)showDialog
       completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [params setValue:backId forKey:@"backId"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/black/blackDeal", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             if ([dictionary objectForKey:@"msg"]) {
                                                 NSString *msg = [dictionary objectForKey:@"msg"];
                                                 [SVProgressHUD showInfoWithStatus:msg];
                                                 if ([msg containsString:@"非法"]) {
                                                     [[AppDelegate appDelegate] toLogin];
                                                 }
                                                 completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                                 return;
                                             } else {
                                                 completionBlock(API_Request_Success, returnData);
                                             }
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)blackDealToken:(NSString *)token
                    id:(NSString *)id1
                backId:(NSString *)backId
             recUserId:(NSString *)recUserId
               reTitle:(NSString *)reTitle
               message:(NSString *)message
            showDialog:(BOOL)showDialog
       completionBlock:(void (^)(int result, id responseObject))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [params setValue:backId forKey:@"backId"];
    [params setValue:recUserId forKey:@"recUserId"];
    [params setValue:reTitle forKey:@"reTitle"];
    [params setValue:message forKey:@"message"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/black/blackDeal", API_HOST]
                                  networkType:NetWorkPOST
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         //[{"flag":"0","msg":"提交成功！"}]
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                               NSDictionary *dictionary = returnData[0];
                                             if ([dictionary[@"flag"] intValue] != 0) {
                                                 NSString *msg = dictionary[@"msg"];
                                                 if ([msg containsString:@"非法"]) {
                                                     [[AppDelegate appDelegate] toLogin];
                                                 }
                                                 completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                                 return;
                                             } else {
                                                 DLog(@"flag=0,提交成功");
                                                 completionBlock(API_Request_Success, returnData);
                                             }
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}

+ (void)blackViewToken:(NSString *)token
                    id:(NSString *)id1
                backId:(NSString *)backId
            showDialog:(BOOL)showDialog
       completionBlock:(void (^)(int, id))completionBlock {
    NSMutableDictionary *params = [self getCommonDic];;
    [params setValue:token forKey:@"token"];
    [params setValue:id1 forKey:@"id"];
    [params setValue:backId forKey:@"backId"];
    [[BMNetworkHandler sharedInstance] conURL:[NSString stringWithFormat:@"%@/black/blackView", API_HOST]
                                  networkType:NetWorkGET
                                       params:params
                                     delegate:nil
                                      showHUD:showDialog
                                 successBlock:^(id returnData) {
                                     if (completionBlock) {
                                         NSError *error;
                                         returnData = [NSJSONSerialization JSONObjectWithData:returnData options:nil error:&error];
                                         if (returnData && [returnData isKindOfClass:[NSArray class]]) {
                                             NSDictionary *dictionary = returnData[0];
                                             if ([dictionary objectForKey:@"msg"]) {
                                                 NSString *msg = [dictionary objectForKey:@"msg"];
                                                 [SVProgressHUD showInfoWithStatus:msg];
                                                 if ([msg containsString:@"非法"]) {
                                                     [[AppDelegate appDelegate] toLogin];
                                                 }
                                                 completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                                 return;
                                             } else {
                                                 completionBlock(API_Request_Success, returnData);
                                             }
                                         } else {
                                             completionBlock(API_COULD_NOT_CONNECT_ERROR, nil);
                                         }
                                     }
                                 } failureBlock:^(NSError *error) {
                if (completionBlock) {
                    completionBlock(error.code, nil);
                }
            }];
}


+ (void)showErrorMsg:(NSInteger)msgCode {
    if (msgCode == -1009) {
        [SVProgressHUD showErrorWithStatus:Error_Network];
    } else {
        [SVProgressHUD showErrorWithStatus:Error_Network];
    }
}


+ (NSMutableDictionary *)getCommonDic {
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    //每个接口必传参数
    NSString *timeStamp = [self dateToTimeStamp:[NSDate date]];
    NSString *sign = [NSString stringWithFormat:@"%@%@", timeStamp, publicKey];
    sign = [DES3Util encrypt:sign];
//    [params setValue:timeStamp forKey:@"timeStamp"];
//    [params setValue:sign forKey:@"sign"];
//    [params setValue:@"02" forKey:@"appKey"];
    return params;
}

//时间转时间戳
+ (NSString *)dateToTimeStamp:(NSDate *)date {
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate:date];
    NSDate *localeDate = [date dateByAddingTimeInterval:interval];
    NSLog(@"%@", localeDate);
    // 时间转换成时间戳
    return [NSString stringWithFormat:@"%ld", (long) [localeDate timeIntervalSince1970]];
}
@end
